<template>
  <div class="not-found-container">
    <!-- 404大号数字 -->
    <div class="error-code">
      <span class="four">4</span>
      <span class="zero">0</span>
      <span class="four">4</span>
    </div>
    
    <!-- 幽默角色 -->
    <div class="character">
      <div class="confused-face">
        <img :src="thinkingFaceEmoji" alt="思考表情" class="emoji-img" />
      </div>
      <div class="speech-bubble">
        <div class="bubble-text">哎呀！这里好像什么都没有呢...</div>
      </div>
    </div>
    
    <!-- 主要内容 -->
    <div class="content">
      <h1 class="title">页面走丢了！</h1>
      <div class="messages">
        <p class="main-message">
          {{ currentMessage }}
        </p>
        <p class="sub-message">
          不过别担心，我们可以帮您找到正确的路！
        </p>
      </div>
      
      <!-- 行动按钮 -->
      <div class="actions">
        <button @click="goHome" class="home-btn">
          <img :src="houseEmoji" alt="房子" class="btn-emoji" /> 回到首页
        </button>
        <button @click="goBack" class="back-btn">
          <img :src="leftArrowEmoji" alt="返回" class="btn-emoji" /> 返回上页
        </button>
        <button @click="changeMessage" class="surprise-btn">
          <img :src="gamesDieEmoji" alt="骰子" class="btn-emoji" /> 换个说法
        </button>
      </div>
    </div>
    
    <!-- 装饰元素 -->
    <div class="floating-elements">
      <div class="element element-1">
        <img :src="magnifyingGlassEmoji" alt="放大镜" class="floating-emoji" />
      </div>
      <div class="element element-2">
        <img :src="roundPushpinEmoji" alt="图钉" class="floating-emoji" />
      </div>
      <div class="element element-3">
        <img :src="worldMapEmoji" alt="世界地图" class="floating-emoji" />
      </div>
      <div class="element element-4">
        <img :src="compassEmoji" alt="指南针" class="floating-emoji" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

// 导入 FluentUI Emoji (SVG格式)
import thinkingFace from 'fluentui-emoji/icons/modern/thinking-face.svg'
import house from 'fluentui-emoji/icons/modern/house.svg'
import leftArrow from 'fluentui-emoji/icons/modern/left-arrow.svg'
import gamesDie from 'fluentui-emoji/icons/modern/game-die.svg'
import magnifyingGlass from 'fluentui-emoji/icons/modern/magnifying-glass-tilted-left.svg'
import roundPushpin from 'fluentui-emoji/icons/modern/round-pushpin.svg'
import worldMap from 'fluentui-emoji/icons/modern/world-map.svg'
import compass from 'fluentui-emoji/icons/modern/compass.svg'

const router = useRouter()

// FluentUI Emoji 变量
const thinkingFaceEmoji = ref(thinkingFace)
const houseEmoji = ref(house)
const leftArrowEmoji = ref(leftArrow)
const gamesDieEmoji = ref(gamesDie)
const magnifyingGlassEmoji = ref(magnifyingGlass)
const roundPushpinEmoji = ref(roundPushpin)
const worldMapEmoji = ref(worldMap)
const compassEmoji = ref(compass)

// 幽默的404提示语列表
const messages = [
  "看起来您要找的页面去度假了，忘记留地址了！",
  "这个页面可能正在和其他页面玩捉迷藏！",
  "哎呀！这个网址好像被外星人劫持了！👽",
  "页面君暂时离开了，可能去买咖啡了 ☕",
  "您寻找的页面正在另一个次元中，请稍后再试！",
  "这里什么都没有，连404都觉得尴尬！",
  "页面可能在堵车，或者迷路了！🚗",
  "抱歉，这个页面正在参加隐身术培训班！",
  "您的请求已到达火星，但火星人说没有这个页面！🚀",
  "这个URL可能需要VIP会员才能访问...开玩笑的！"
]

const currentMessage = ref('')

// 随机选择一个消息
const getRandomMessage = () => {
  const randomIndex = Math.floor(Math.random() * messages.length)
  return messages[randomIndex]
}

// 更换消息
const changeMessage = () => {
  let newMessage = getRandomMessage()
  // 确保不重复显示相同的消息
  while (newMessage === currentMessage.value && messages.length > 1) {
    newMessage = getRandomMessage()
  }
  currentMessage.value = newMessage
}

// 返回首页
const goHome = () => {
  router.push('/')
}

// 返回上一页
const goBack = () => {
  if (window.history.length > 1) {
    router.go(-1)
  } else {
    goHome()
  }
}

// 页面加载时设置初始消息
onMounted(() => {
  currentMessage.value = getRandomMessage()
})
</script>

<style scoped>
.not-found-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* 404数字样式 */
.error-code {
  font-size: 8rem;
  font-weight: 900;
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
  text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.1);
}

.four {
  color: #e74c3c;
  animation: wobble 2s infinite ease-in-out;
}

.zero {
  color: #f39c12;
  animation: wobble 2s infinite ease-in-out 0.3s;
}

.four:last-child {
  color: #3498db;
  animation: wobble 2s infinite ease-in-out 0.6s;
}

@keyframes wobble {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-5deg);
  }
  75% {
    transform: rotate(5deg);
  }
}

/* 角色和对话框 */
.character {
  position: relative;
  margin-bottom: 40px;
}

.confused-face {
  animation: bounce 2s infinite;
}

.emoji-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.speech-bubble {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  padding: 10px 15px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  font-size: 0.9rem;
  color: #666;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: white;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-15px);
  }
  60% {
    transform: translateY(-7px);
  }
}

/* 主要内容 */
.content {
  text-align: center;
  max-width: 600px;
  background: rgba(255, 255, 255, 0.9);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}

.title {
  font-size: 2.5rem;
  font-weight: bold;
  color: #2c3e50;
  margin-bottom: 20px;
}

.messages {
  margin-bottom: 30px;
}

.main-message {
  font-size: 1.2rem;
  color: #34495e;
  margin-bottom: 15px;
  line-height: 1.6;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sub-message {
  font-size: 1rem;
  color: #7f8c8d;
  line-height: 1.5;
}

/* 按钮样式 */
.actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.actions button {
  padding: 12px 24px;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-emoji {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.home-btn {
  background: linear-gradient(45deg, #3498db, #2980b9);
  color: white;
}

.home-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.back-btn {
  background: linear-gradient(45deg, #95a5a6, #7f8c8d);
  color: white;
}

.back-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(149, 165, 166, 0.4);
}

.surprise-btn {
  background: linear-gradient(45deg, #e74c3c, #c0392b);
  color: white;
}

.surprise-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

/* 浮动装饰元素 */
.floating-elements {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.element {
  position: absolute;
  opacity: 0.6;
  animation: float 6s ease-in-out infinite;
}

.floating-emoji {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.element-1 {
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

.element-2 {
  top: 30%;
  right: 15%;
  animation-delay: 1s;
}

.element-3 {
  bottom: 25%;
  left: 20%;
  animation-delay: 2s;
}

.element-4 {
  bottom: 15%;
  right: 10%;
  animation-delay: 3s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  33% {
    transform: translateY(-20px) rotate(5deg);
  }
  66% {
    transform: translateY(-10px) rotate(-5deg);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .error-code {
    font-size: 6rem;
    gap: 5px;
  }
  
  .title {
    font-size: 2rem;
  }
  
  .content {
    padding: 30px 20px;
    margin: 0 10px;
  }
  
  .actions {
    flex-direction: column;
    align-items: center;
  }
  
  .actions button {
    width: 100%;
    max-width: 200px;
  }
  
  .speech-bubble {
    font-size: 0.8rem;
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  .error-code {
    font-size: 4rem;
  }
  
  .emoji-img {
    width: 60px;
    height: 60px;
  }
  
  .title {
    font-size: 1.5rem;
  }
  
  .main-message {
    font-size: 1rem;
    min-height: 50px;
  }
  
  .floating-emoji {
    width: 30px;
    height: 30px;
  }
  
  .btn-emoji {
    width: 16px;
    height: 16px;
  }
}
</style>
